<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:include page="../Common/header.jsp"></jsp:include>
<!-- Content Wrapper. Contains page content -->


<!-- 确认删除模态框 -->


<div id="delDialog" class="modal">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-label="Close">
					<span aria-hidden="true">×</span>
				</button>
				<h4 class="modal-title">提示</h4>
			</div>
			<div class="modal-body">
				<p>是否确认删除</p>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default pull-left"
					data-dismiss="modal">取消</button>
				<button onclick="del()" type="button" class="btn btn-primary">确认</button>
			</div>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal-dialog -->
</div>

<!-- 确认删除模态框 -->

<!-- 导入Excel -->


<div id="import" class="modal">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-label="Close">
					<span aria-hidden="true">×</span>
				</button>
				<h4 class="modal-title">导入Excel</h4>
			</div>
			<form method="post" enctype="multipart/form-data" action="<c:url value="/Supplier/import" />">
			<div class="modal-body">
			   <label>警告：请先下载模板再导入</label> <a href="<c:url value="/Common/download?fileName=supplier.xlsx" />" class="btn btn-primary" >下载模版</a><br/><br/>
				<input name="file" type="file">
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default pull-left"
					data-dismiss="modal">取消</button>
				<input type="submit"  class="btn btn-primary" value="导入">
				
			</div>
			</form>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal-dialog -->
</div>

<!-- 导入Excel -->


<!-- 新增用户模态框 -->


<div id="addUserDialog" class="modal">
	<div class="modal-dialog">
		<div class="modal-content">
			<form method="post" action="<c:url value="/Supplier/add" />">
			<div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">×</span></button>
                <h4 class="modal-title">增加供应商</h4>
              </div>
					<div class="box-body">
					                
						<div class="form-group col-xs-6">
							<label for="password">公司名称*:</label> <input type="text"
								class="form-control" name="companyName" id="companyName"
								placeholder="公司名称">
						</div>
						<div class="form-group col-xs-6">
							<label for="repassword">公司简称*：</label> <input type="text"
								class="form-control" name="shortName" id="shortName"
								placeholder="公司简称">
						</div>
						<div class="form-group col-xs-6">
							<label for="password">帐号*:</label> <input type="text"
								class="form-control" name="account" id="account"
								placeholder="帐号">
						</div>
						<div class="form-group col-xs-6">
							<label for="password">税号*:</label> <input type="text"
								class="form-control" name="taxNumber" id="taxNumber"
								placeholder="税号">
						</div>
						<div class="form-group col-xs-6">
							<label for="password">付款方式:</label> <input type="text"
								class="form-control" name="payType" id="accountName"
								placeholder="付款方式">
						</div>
						<div class="form-group col-xs-6">
							<label for="password">地址：</label> <input type="text"
								class="form-control" name="address" id="address"
								placeholder="地址">
						</div>
						<div class="form-group col-xs-6">
							<label for="password">联系人:</label> <input type="text"
								class="form-control" name="contacts" id="contacts"
								placeholder="联系人">
						</div>
						<div class="form-group col-xs-6">
							<label for="password">邮箱:</label> <input type="text"
								class="form-control" name="email" id="email"
								placeholder="邮箱">
						</div>
						<div class="form-group col-xs-6">
							<label for="password">办公电话:</label> <input type="text"
								class="form-control" name="phone" id="phone"
								placeholder="办公电话">
						</div>
						<div class="form-group col-xs-6">
							<label for="password">手机:</label> <input type="text"
								class="form-control" name="mobilePhone" id="mobilePhone"
								placeholder="手机">
						</div>
						<div class="form-group col-xs-6">
							<label for="password">传真:</label> <input type="text"
								class="form-control" name="fax" id="fax"
								placeholder="传真">
						</div>
						<div class="form-group col-xs-6">
							<label for="password">即时聊天:</label> <input type="text"
								class="form-control" name="qq" id="qq"
								placeholder="即时聊天">
						</div>
						
							<div class="form-group col-xs-12">
							<label for="password">其他:</label> <textarea rows="8"
								class="form-control" name="etc" id="etc"
								></textarea>
						</div>
						

					</div>
					<!-- /.box-body -->

					<div class="box-footer">
						<button type="submit" class="btn btn-primary">增加</button>
					</div>
				</form>
			
			
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal-dialog -->
</div>

<!-- 新增用户模态框 -->


<div class="content-wrapper">
	<section class="content-header">
		<h1>供应商</h1>
		<ol class="breadcrumb">
			<li><a href="<c:url value="/Admin/index" />"><i
					class="fa fa-dashboard"></i> Home</a></li>

			<c:forEach items="${routers}" var="router">
				<li><i class="${router.icon}"></i><a href="javascript:void(0)">&nbsp&nbsp${router.name
						}</a></li>
			</c:forEach>

		</ol>
	</section>

	<section class="content">

		<div class="page-header clearfix">
			<h1 class="col-sm-8"></h1>
		
		</div>
		<form method="post" id="form_adv_search" name="form_adv_search">
			<input type="hidden" name="ajax" id="ajax" value="1">
			<div class="operate panel panel-default">
				<div class="panel-body">
					<div class="pull-left form-inline">
						
						<a data-toggle="modal" data-toggle="modal" data-target="#import" class="btn btn-sm btn-primary">导入Excel</a>
					</div>
					<div class="pull-right">
						<a  	data-toggle="modal" data-target="#addUserDialog" class="btn btn-sm btn-primary">新增</a> | <a
						data-toggle="modal" data-target="#delDialog"
						class="btn btn-sm btn-danger">删除</a>
					</div>
				</div>
			</div>
		</form>
		<div class="box">
			<div class="box-body">


				

				<div class="col-sm-12">
					<table id="userstable" class="table table-bordered table-hover">
						<thead>
							<tr>
								<th>公司名称</th>
								<th>税号</th>
								<th>联系人</th>
								<th>办公电话 / 电话</th>

							</tr>
						</thead>
						<tbody>
						<c:forEach var="supplier" items="${suppliers}">
							<tr id="${supplier.id }">
							<td><a href="<c:url value="/Supplier/view/${supplier.id}" />">${supplier.companyName}</a></td>
								<td>${supplier.taxNumber }</td>
								<td>${supplier.contacts }</td>
								<td>${supplier.phone} / ${supplier.mobilePhone}</td>
							</tr>
							</c:forEach>
						</tbody>
					</table>
				</div>
                 <input type="hidden" id="id" />


			</div>
		</div>
	</section>

</div>
<!-- /.content-wrapper -->
<jsp:include page="../Common/footer.jsp"></jsp:include>
<script type="text/javascript">
	
	
	$.ajaxSetup({   
        contentType:"application/x-www-form-urlencoded;charset=utf-8",   
        complete:function(XMLHttpRequest,textStatus){ 
          var sessionstatus=XMLHttpRequest.getResponseHeader("sessionstatus"); //通过XMLHttpRequest取得响应头，sessionstatus，  
              if(sessionstatus=="timeout"){ 
                  alert("登录超时,请重新登录！");
              //如果超时就处理 ，指定要跳转的页面  
                window.location.reload();   
              }   
           }   
      }); 

	$('#userstable').DataTable({
		"initComplete": function () {
            var api = this.api();
            api.$('tr').click( function () {
            	 api.$('tr').attr("class", "");
        		$(this).attr("class", "active");
        				$("#id").val($(this).attr("id"));
        		
            } );
        },
		"paging" : true,
		"lengthChange" : true,
		"searching" : true,
		"ordering" : true,
		"info" : true,
		"autoWidth" : false,
		"language": {  
			"sLengthMenu": "每页显示  _MENU_ 条记录",  
            "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
                },
            "sZeroRecords": "抱歉， 没有找到",
            "sInfoEmpty": "没有数据"}
	});
	
	

	
	function del() {
		if ($("#id").val() == "") {
			alert("请先选择要删除的供应商");
			return;
		}
		window.location.href = "<c:url value="/Supplier/delete" />" + "?id="
				+ $("#id").val();
	}
	
	

</script>

